package cn.stylefeng.guns.modular.flowable.service.impl;

import cn.stylefeng.guns.core.common.page.LayuiPageFactory;
import cn.stylefeng.guns.core.common.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.flowable.entity.ActHiTaskinst;
import cn.stylefeng.guns.modular.flowable.mapper.ActHiTaskinstMapper;
import cn.stylefeng.guns.modular.flowable.model.params.ActHiTaskinstParam;
import cn.stylefeng.guns.modular.flowable.model.result.ActHiTaskinstResult;
import cn.stylefeng.guns.modular.flowable.service.ActHiTaskinstService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sxh
 * @since 2019-12-21
 */
@Service
public class ActHiTaskinstServiceImpl extends ServiceImpl<ActHiTaskinstMapper, ActHiTaskinst> implements ActHiTaskinstService {

    @Override
    public void add(ActHiTaskinstParam param){
        ActHiTaskinst entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(ActHiTaskinstParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(ActHiTaskinstParam param){
        ActHiTaskinst oldEntity = getOldEntity(param);
        ActHiTaskinst newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public ActHiTaskinstResult findBySpec(ActHiTaskinstParam param){
        return null;
    }

    @Override
    public List<ActHiTaskinstResult> findListBySpec(ActHiTaskinstParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(ActHiTaskinstParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(ActHiTaskinstParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private ActHiTaskinst getOldEntity(ActHiTaskinstParam param) {
        return this.getById(getKey(param));
    }

    private ActHiTaskinst getEntity(ActHiTaskinstParam param) {
        ActHiTaskinst entity = new ActHiTaskinst();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
